using UnityEngine;
using System.Collections;

public class Cannon : MonoBehaviour {

    private float currentTime;
	private bool isDelayTime;
	
	public float delay, interval = 2, speed = 0.25f;
    public GameObject bullet;
	public Vector3 posFinal;

	// Update is called once per frame
	void FixedUpdate () {
        currentTime += Time.deltaTime;
		
		//Se o cronometro alcançou o tempo de delay.
		if (currentTime > delay && !isDelayTime)
		{
			//Zera o cronometro.
			currentTime = 0;
			isDelayTime = true;
		}

        if (currentTime >= interval)
        {
            currentTime = 0;
            GameObject tempBullet = Instantiate(bullet, transform.position, transform.rotation) as GameObject;
            //Parâmetros para a bala instanciada de posição e velocidade
			tempBullet.GetComponent<Bullet>().posicaoFinal = posFinal;
            tempBullet.GetComponent<Bullet>().speed = speed;
        }
	}
}